package wusiyuan.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;

import entity.User_Address;
import wusiyuan.service.ChangeTheAddressService;
import wusiyuan.service.GetTheAddressService;
import wusiyuan.service.impl.ChangeTheAddressServiceImpl;
import wusiyuan.service.impl.GetTheAddressServiceImpl;

/**
 * Servlet implementation class GetTheAddressServlet
 */
public class GetTheAddressServlet extends HttpServlet {
	private GetTheAddressService gta =new GetTheAddressServiceImpl();
	private	ChangeTheAddressService ct  = new ChangeTheAddressServiceImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("utf-8");
		String consignee = request.getParameter("consignee");
		String phone = request.getParameter("phone");
		User_Address ua = gta.selectAddressByconsigneeAndPhone(consignee, phone);
		response.getWriter().print(JSON.toJSONString(ua));
		HttpSession session = request.getSession(); 
		session.setAttribute("User_AddressId" ,ua.getUser_addr_id());	
		session.setAttribute("city" ,ua.getCity());
		session.setAttribute("district" ,ua.getDistrict());

	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		doGet(request, response);
	}

}
